﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace IssuesClient
{
    /// <summary>
    /// Interaction logic for IssueWindow.xaml
    /// </summary>
    public partial class IssueWindow : Window
    {
        public IssueWindow()
        {
            InitializeComponent();
            this.DataContext = new IssueServiceReference.Issue(); //Has to be changed for edit!!!!!
            this.IssueCreationDateTextBox.Text = System.DateTime.Now.ToString();
            
            this.IssueDueDateDatePicker.DisplayDate = new DateTime(2009, 5, 1);
            this.IssueDueDateDatePicker.DisplayDateStart = new DateTime(2009, 1, 1);
            this.IssueDueDateDatePicker.DisplayDateEnd = new DateTime(2009, 1, 31);
        }

        /// <summary>
        /// Helper method to validate the confirma button. The confirm button will only be available when all the parameters are met.
        /// </summary>
        private void validate()
        {
            bool text_valid = (this.IssueNameTextBox.Text != string.Empty && this.IssueCreationDateTextBox.Text != string.Empty);
            bool comboBox_valid = (this.IssueStatusComboBox.SelectedItem != null && this.IssueAssignToComboBox.SelectedItem != null);
            bool numbers_valid = (this.HoursLeftToGoTextBox.Text != string.Empty && this.HoursWorkedTextBox.Text != string.Empty);
            this.OKButton.IsEnabled = text_valid && comboBox_valid && numbers_valid;
        }

        /// <summary>
        /// Method fired when text is entered or changed in the textboxes. It will call validate so we can enable the confirm button or not
        /// </summary>
        private void Validate_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.validate();
        }

        /// <summary>
        /// Method fired when item is selected in the combo boxes. It will call validate so we can enable the confirm button or not
        /// </summary>
        private void Validate_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.validate();
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

    }
}
